from fastapi import UploadFile
from sqlalchemy.orm import Session
from app.db.db_models import Resources
from typing import Optional

class DBResources:
    def __init__(self, session: Session):
        self.session = session

    def get_resources(self, resource_id: int = None) -> Optional[Resources]:
        if resource_id:
            return self.session.query(Resources).filter(Resources.id == resource_id).first()
        else:
            return self.session.query(Resources).all()

    def add_resource(self, name: str, user_id: int) -> Resources:
        new_resource = Resources(name=name, user_id=user_id)
        self.session.add(new_resource)
        self.session.commit()
        self.session.refresh(new_resource)
        return new_resource

    def delete_resource(self, resource_id: int) -> None:
        self.session.query(Resources).filter(Resources.id == resource_id).delete()
        self.session.commit()

 

